#!/usr/bin/env python

import sys
import utils
import pprint
import sqlite3
import os


def main(args=None):
    if args == None:
        args = sys.argv[1:]

        fileMap = utils.getEquivalenceMap()


        conn = sqlite3.connect(os.path.abspath('equivalenceMap.sq3'))
        c = conn.cursor()

        #c.execute('''create table if not exists items (title text, number text)''')

        c.execute('''create table if not exists item_map (key text, number text)''')
        c.execute('''create unique index if not exists item_map_unique on item_map (key, number)''')


        for number, values in fileMap.items():
            print values[0], number
            
            try:
                c.execute('insert into item_map values (?, ?)', (values[0], number))
            except:
                raise

        conn.commit()
    return 0




if __name__ == '__main__':
    sys.exit(main())

